use iced::{Application, Element, Error, Length, Sandbox, Settings, Theme, widget};
use iced::widget::{Column, Container, Row, Text};

pub struct Gift {
    content: String,
}


#[derive(Debug, Clone)]
pub enum Message {
    FUNCTION1,
    FUNCTION2,
    FUNCTION3,
}


impl Sandbox for Gift {
    type Message = Message;

    fn new() -> Self {
        Gift {
            content: "waiting...".to_string(),
        }
    }

    fn title(&self) -> String {
        String::from("给程序员的礼物")
    }

    fn update(&mut self, message: Self::Message) {
        match message {
            Message::FUNCTION1 => {
                self.content = String::from("功能1");
            }
            Message::FUNCTION2 => {
                self.content = String::from("功能2");
            }
            Message::FUNCTION3 => {
                self.content = String::from("功能3");
            }
        }
    }

    fn view(&self) -> Element<'_, Self::Message> {
        let btn1 = widget::button("功能1").on_press(Message::FUNCTION1);
        let btn2 = widget::button("功能2").on_press(Message::FUNCTION2);
        let btn3 = widget::button("功能3").on_press(Message::FUNCTION3);

        let left_column = Column::new()
            .push(btn1)
            .push(btn2)
            .push(btn3)
            .padding(20)
            .width(Length::FillPortion(1)); // 左侧占 20%

        // 右侧内容
        let right_container = Container::new(Text::new(&self.content).size(50))
            .padding(20)
            .width(Length::FillPortion(4)); // 右侧占 80%

        // 左右分隔布局
        let layout = Row::new()
            .push(left_column)
            .push(right_container)
            .width(Length::Fill)
            .height(Length::Fill)
            .spacing(20);

        Container::new(layout)
            .width(Length::Fill)
            .height(Length::Fill)
            .center_x()
            .center_y()
            .into()
    }
}
